//
//  AppDelegate.m
//  Atlantis
//
//  Created by  亚特兰蒂斯 on 14-12-17.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"
#import "FinderViewController.h"
#import "CollectViewController.h"
#import "PlayViewController.h"
#import <ShareSDK/ShareSDK.h>
#import "WeiboSDK.h"


@interface AppDelegate ()<UITabBarControllerDelegate>

@property(nonatomic, retain)UITabBarController *tabBarController;


@end

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
     [NSThread sleepForTimeInterval:1];
    // 创建主屏幕
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    // 设置背景颜色为白色
    self.window.backgroundColor = [UIColor whiteColor];
    // 使窗口可见
    [self.window makeKeyAndVisible];
    [_window release];

    // 创建一个tabBarController对象
    self.tabBarController = [[UITabBarController alloc] init];
    // 设置tabbar的代理为self
    self.tabBarController.delegate = self;
    
    // 创建Finder视图控制器对象
    FinderViewController *finderVC = [[FinderViewController alloc] init];
    // 设置Finder 的tabbar标题
    finderVC.tabBarItem.title = @"主页";
    // 设置图片
    finderVC.tabBarItem.image = [UIImage imageNamed:@"shouye.png"];
    
    // 创建我的页面
    CacheViewController *cacheVC = [[CacheViewController alloc] init];
    // 设置标题
    cacheVC.tabBarItem.title = @"我的";
    // 设置图标
    cacheVC.tabBarItem.image = [UIImage imageNamed:@"user.png"];
    
    
    // 创建一个导航控制器, 初始化finderVC作为导航控制器的根视图控制器
    UINavigationController *naviC = [[UINavigationController alloc] initWithRootViewController:finderVC];
    // 内存管理
    [finderVC release];
    
    // 创建导航控制器, 初始化cacheVC为导航控制器的根视图控制器
    UINavigationController *cacheNav = [[UINavigationController alloc] initWithRootViewController:cacheVC];
    // 内存管理
    [cacheVC release];
    
    // 创建一个数组, 用来存储tabbar中要显示的viewController
    NSArray *arr = [NSArray arrayWithObjects:naviC, cacheNav, nil];
 
    
    // 给tabbar的viewControllers赋值
    self.tabBarController.viewControllers = arr;
    // 将tabbar设置为window的根视图控制器
    self.window.rootViewController = self.tabBarController;
    
    // 创建一个JingRoundView对象
    self.roundView = [[JingRoundView alloc] initWithFrame:CGRectMake(self.window.frame.size.width / 2 - 35, -21, 70, 70)];
    self.roundView.backgroundColor = [UIColor redColor];
    // 为JingRoundView指定代理人
    self.roundView.delegate = self;
    // 设置roundImage
    self.roundView.roundImage = [UIImage imageNamed:@"tubiao*2.png"];
    // 设置旋转一周所需时间
    self.roundView.rotationDuration = 8.0;
    // 设置旋转状态, 暂停
    self.roundView.isPlay = NO;

    // 将roundView添加到tabBar上
    [self.tabBarController.tabBar addSubview:self.roundView];
    // 标识tag值
    self.roundView.tag = 100;
    // 内存管理
    [_roundView release];
    
    // 释放内存
    [_tabBarController release];
    
    
    
    //字符串api20为您的ShareSDK的AppKey
    [ShareSDK registerApp:@"4f40646c04d0"];
    
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"1119346363" appSecret:@"e5832485bd31e9d2365528aeb90c3053" redirectUri:@"http://www.sharesdk.cn"];
    //当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
    [ShareSDK  connectSinaWeiboWithAppKey:@"1119346363" appSecret:@"e5832485bd31e9d2365528aeb90c3053" redirectUri:@"http://www.sharesdk.cn" weiboSDKCls:[WeiboSDK class]];
    
 
    return YES;
}

-(void)playStatuUpdate:(BOOL)playState
{
    // 通过单例创建一个PlayViewController对象
    PlayViewController *play = [PlayViewController sharePlayVC];
    // 判断旋转状态
    if (playState) {
        // 如果播放, play播放
        [play playButtonClicked:nil];
    } else {
        // 否则, play暂停
        [play pauseButtonClicked:nil];
    }
    NSLog(@"%@...", playState ? @"播放": @"暂停了");
}


// 属性的内存管理
- (void)dealloc
{
    [_window release];
    [_tabBarController release];
    [_roundView release];
    
    [super dealloc];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
